package pojo.postman;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Data
public class PostManPojo {
    private PostManFirstInfo info;
    private List<PostManFirsItem> item = new ArrayList<>();

    public PostManFirsItem getFirstByKey(String key) {
        for (PostManFirsItem firstItem : item) {
            if(key.equals(firstItem.getName())){
                return firstItem;
            }
        }
        PostManFirsItem firstItem = new PostManFirsItem(key, new ArrayList<>());
        item.add(firstItem);
        return firstItem;
    }

    public PostManPojo(PostManFirstInfo info) {
        this.info = info;
        this.item = new ArrayList<>();
    }

    public PostManPojo() {
    }

    public PostManFirstInfo getInfo() {
        return info;
    }

    public void setInfo(PostManFirstInfo info) {
        this.info = info;
    }

    public List<PostManFirsItem> getItem() {
        item = Optional.ofNullable(item).orElse(new ArrayList<>());
        return item;
    }

    public void setItem(List<PostManFirsItem> item) {
        this.item = item;
    }
}
